package com.ninetaildemonfox.zdl.socialproject.mvp.presenter;

import android.support.v7.app.AppCompatActivity;

import com.google.gson.JsonObject;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.kongzue.dialog.v3.WaitDialog;
import com.ninetaildemonfox.zdl.socialproject.config.Constants;
import com.ninetaildemonfox.zdl.socialproject.http.https.Model;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.DetaillnterfaceContract;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;
import com.ninetaildemonfox.zdl.socialproject.utils.dialog.DialogShow;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 创建人： Nine tails fox
 * 创建时间： 2019/8/9
 * 功能描述：
 * 联系方式：1037438704@qq.com
 *
 * @author NineTailDemonFox
 */

public class DetaillnterfacePresenter {
    private AppCompatActivity me;
    private DetaillnterfaceContract contract;

    public DetaillnterfacePresenter(AppCompatActivity me, DetaillnterfaceContract contract) {
        this.me = me;
        this.contract = contract;
    }

    public void getMemberInfo(String token, String member_id, String lon, String lat) {
        Model.getInstance().getUserApi().getMemberInfo(token, member_id, lon, lat)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        WaitDialog.dismiss();
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null) {
                            return;
                        }
                        Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                        contract.DetaSuccess(data);
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {
                        WaitDialog.dismiss();
                        ToastUtil.show("您的网络不佳，请稍候重试");
                    }
                });
    }

    /**
     * 添加收藏
     */
    public void addMylike(String token, String cover_member_id) {
        Model.getInstance()
                .getUserApi()
                .addMylike(token, cover_member_id)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null) {
                            return;
                        }
                        ToastUtil.show(map.get("message"));
                        contract.memberInfor();
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {

                    }
                });
    }

    /**
     * 查看用户社交账号
     * token	用户 token	否	文本	未提供
     cover_member_id	被查看人的用户 id	否	文本	未提供
     type	1聊天 2查看社交账号 3解锁相册	否	文本	未提供
     do_type	1查看 2使用
     * */
    public void getisPay(String token,String cover_member_id,String type,String do_tyep){
        Model.getInstance().getUserApi().isPay(token,cover_member_id,type,do_tyep)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null){
                            return;
                        }
                        Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                        contract.isPay(data,type,do_tyep);
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {

                    }
                });
    }

}
